home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / DATATYPE.SWG / 0002_BIGHEAP.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  4KB  |  111 lines

  1. {    ...Here is a demo Program that will read-in up to 15,000 Records
  2.     onto the HEAP memory pool.
  3. }
  4.  
  5. {$A+,B-,D+,E-,F-,G-,I+,L+,N-,O-,P-,Q+,R+,S+,T-,V-,X-,Y-}
  6. {$M 4096,0,655360}
  7.  
  8. Program Large_Array_Structure_Demo;
  9.  
  10. Type
  11.               (* Type definitions.                                    *)
  12.   st_8    = String[8];
  13.   inar_4  = Array[0..4] of Integer;
  14.  
  15.   rc_zlog = Record
  16.               date      : String[8];
  17.               userbaud  : inar_4;
  18.               active    : Integer;
  19.               calls     : Integer;
  20.               newusers  : Integer;
  21.               pubpost   : Integer;
  22.               privpost  : Integer;
  23.               netpost   : Integer;
  24.               criterr   : Integer;
  25.               uploads   : Integer;
  26.               downloads : Integer;
  27.               uk        : LongInt;
  28.               dk        : LongInt
  29.             end;
  30.  
  31. Const
  32.               (* Maximum number of Records to read-in.                *)
  33.   co_rcMax   = 15000;
  34.               (* Byte size of 1 Record.                               *)
  35.   co_rcSize  = sizeof(rc_zlog);
  36.  
  37. Type
  38.               (* Pointer of zlog Record Type.                         *)
  39.   porc_zlog  = ^rc_zlog;
  40.               (* Array of 15,000 of zlog-Record Pointers.             *)
  41.   poar_15K   = Array[1..co_rcMax] of porc_zlog;
  42.  
  43. Var
  44.               (* Use to store "ioresult" value.                       *)
  45.   by_Error          : Byte;
  46.               (* Loop control Variable.                               *)
  47.   wo_Index,
  48.               (* Total number of Records in the data File.            *)
  49.   wo_RecTotal,
  50.               (* Number of Bytes read using "BlockRead" routine.      *)
  51.   wo_BytesRead      : Word;
  52.               (* Pointer to mark the bottom of the HEAP.              *)
  53.   po_HeapBottom     : Pointer;
  54.               (* Array of 15,000 zlog-Record Pointers.                *)
  55.   poar_RcBuffer     : poar_15K;
  56.               (* File Variable to be assigned to the data File.       *)
  57.   fi_Data           : File;
  58.  
  59. begin
  60.               (* Try to open the data File.                           *)
  61.   assign(fi_Data, 'ZLOG.DAT');
  62.   {$I-}
  63.   reset(fi_Data, 1);
  64.   {$I+}
  65.               (* Check For File errors.                               *)
  66.   by_Error := ioresult;
  67.   if (by_Error <> 0) then
  68.   begin
  69.     Writeln('Error ', by_Error, ' opening ZLOG.DAT File');
  70.     halt
  71.   end;
  72.  
  73.               (* Calculate the number of Records in data File.        *)
  74.   wo_RecTotal := (Filesize(fi_Data) div co_rcSize);
  75.               (* Initialize loop control Variable.                    *)
  76.   wo_Index := 1;
  77.               (* Record the address of the HEAP "bottom".             *)
  78.   mark(po_HeapBottom);
  79.               (* While free memory is greater than size of 1 Record   *)
  80.   While (maxavail > co_rcSize)
  81.               (* And, not all Records have been read in...            *)
  82.   and   (wo_Index < wo_RecTotal)
  83.               (* And, less than maximum number of Records to read-in. *)
  84.   and   (wo_Index < co_rcMax) do
  85.   begin
  86.             (* Allocate room For 1 Record on the HEAP.              *)
  87.     new(poar_RcBuffer[wo_Index]);
  88.             (* Read 1 Record from data File into new HEAP Variable. *)
  89.     blockread(fi_Data, poar_RcBuffer[wo_Index]^, co_rcSize, wo_BytesRead);
  90.             (* Check For "BlockRead" error.                         *)
  91.     if (wo_BytesRead <> co_rcSize) then
  92.     begin
  93.       Writeln('BLOCKREAD error!');
  94.       halt
  95.     end;
  96.             (* Advance loop control Variable by 1.                  *)
  97.     inc(wo_Index)
  98.   end;
  99.               (* Close the data File.                                 *)
  100.   close(fi_Data);
  101.               (* Display the amount of free HEAP memory left.         *)
  102.   Writeln('Free HEAP memory = ', maxavail, ' Bytes');
  103.               (* Display the number of Records read onto the HEAP.    *)
  104.   Writeln('Records placed on the HEAP = ', wo_Index);
  105.               (* Release all the HEAP memory used to store Records.   *)
  106.   release(po_HeapBottom);
  107.               (* Display the amount of free HEAP memory left, again.  *)
  108.   Writeln('Free HEAP memory = ', maxavail, ' Bytes');
  109.  
  110. end.
  111.